#version 150

in vec4 color;
out vec4 fcolor;

in vec3 pos;
in vec3 N,L,E,H;
uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct;

//Only here to not break the other shader
uniform int Shades;

uniform int flag;
uniform int selectionColorR;
uniform int selectionColorG;
uniform int selectionColorB;
uniform int selectionColorA;
uniform float Shininess;

void main()
{
    vec4 ambient,diffuse,specular;

    // Compute terms in the illumination equation
    ambient = AmbientProduct;

    float Kd = max( dot(L, N), 0.0 );
    diffuse = Kd*DiffuseProduct;

    float Ks = pow( max(dot(N,H), 0.0), Shininess );
    specular = Ks * SpecularProduct;

    if( dot(L, N) < 0.0 ) {
	specular = vec4(0.0, 0.0, 0.0, 1.0);
    }

    if(flag == 1){
        fcolor.r = float(selectionColorR)/float(255);
        fcolor.g = float(selectionColorG)/float(255);
        fcolor.b = float(selectionColorB)/float(255);
        fcolor.a = float(selectionColorA)/float(255);
    }else{
        fcolor = ambient + diffuse + specular;
        fcolor.a = 1.0;
    }
}

